home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / 3dtabs / iniview.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-07  |  13.2 KB  |  484 lines

  1. VERSION 2.00
  2. Begin Form Iniviewer 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "IniViewer"
  6.    ClientHeight    =   3870
  7.    ClientLeft      =   330
  8.    ClientTop       =   825
  9.    ClientWidth     =   7095
  10.    Height          =   4560
  11.    Icon            =   INIVIEW.FRX:0000
  12.    Left            =   270
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    ScaleHeight     =   258
  16.    ScaleMode       =   3  'Pixel
  17.    ScaleWidth      =   473
  18.    Top             =   195
  19.    Visible         =   0   'False
  20.    Width           =   7215
  21.    Begin PictureBox page 
  22.       Height          =   5580
  23.       Left            =   240
  24.       ScaleHeight     =   5550
  25.       ScaleWidth      =   8985
  26.       TabIndex        =   6
  27.       Top             =   720
  28.       Width           =   9015
  29.       Begin TextBox t 
  30.          FontBold        =   0   'False
  31.          FontItalic      =   0   'False
  32.          FontName        =   "MS Sans Serif"
  33.          FontSize        =   8.25
  34.          FontStrikethru  =   0   'False
  35.          FontUnderline   =   0   'False
  36.          Height          =   5300
  37.          HideSelection   =   0   'False
  38.          Index           =   1
  39.          Left            =   4485
  40.          MultiLine       =   -1  'True
  41.          ScrollBars      =   3  'Both
  42.          TabIndex        =   0
  43.          Top             =   255
  44.          Width           =   4530
  45.       End
  46.       Begin TextBox t 
  47.          FontBold        =   0   'False
  48.          FontItalic      =   0   'False
  49.          FontName        =   "MS Sans Serif"
  50.          FontSize        =   8.25
  51.          FontStrikethru  =   0   'False
  52.          FontUnderline   =   0   'False
  53.          ForeColor       =   &H00000000&
  54.          Height          =   5300
  55.          HideSelection   =   0   'False
  56.          Index           =   0
  57.          Left            =   0
  58.          MultiLine       =   -1  'True
  59.          ScrollBars      =   3  'Both
  60.          TabIndex        =   1
  61.          Top             =   255
  62.          Width           =   4500
  63.       End
  64.       Begin Label ttl 
  65.          BackColor       =   &H00C0C0C0&
  66.          BorderStyle     =   1  'Fixed Single
  67.          FontBold        =   0   'False
  68.          FontItalic      =   0   'False
  69.          FontName        =   "MS Sans Serif"
  70.          FontSize        =   8.25
  71.          FontStrikethru  =   0   'False
  72.          FontUnderline   =   0   'False
  73.          Height          =   255
  74.          Index           =   1
  75.          Left            =   4485
  76.          TabIndex        =   4
  77.          Top             =   0
  78.          Width           =   4530
  79.       End
  80.       Begin Label ttl 
  81.          BackColor       =   &H00C0C0C0&
  82.          BorderStyle     =   1  'Fixed Single
  83.          FontBold        =   0   'False
  84.          FontItalic      =   0   'False
  85.          FontName        =   "MS Sans Serif"
  86.          FontSize        =   8.25
  87.          FontStrikethru  =   0   'False
  88.          FontUnderline   =   0   'False
  89.          Height          =   255
  90.          Index           =   0
  91.          Left            =   0
  92.          TabIndex        =   5
  93.          Top             =   0
  94.          Width           =   4500
  95.       End
  96.    End
  97.    Begin PictureBox tabbox 
  98.       BackColor       =   &H00C0C0C0&
  99.       BorderStyle     =   0  'None
  100.       ClipControls    =   0   'False
  101.       Height          =   495
  102.       Left            =   0
  103.       ScaleHeight     =   33
  104.       ScaleMode       =   3  'Pixel
  105.       ScaleWidth      =   529
  106.       TabIndex        =   2
  107.       Top             =   0
  108.       Width           =   7935
  109.       Begin PictureBox invbox 
  110.          AutoRedraw      =   -1  'True
  111.          BackColor       =   &H00C0C0C0&
  112.          BorderStyle     =   0  'None
  113.          ClipControls    =   0   'False
  114.          Height          =   255
  115.          Left            =   1800
  116.          ScaleHeight     =   17
  117.          ScaleMode       =   3  'Pixel
  118.          ScaleWidth      =   81
  119.          TabIndex        =   3
  120.          Top             =   120
  121.          Visible         =   0   'False
  122.          Width           =   1215
  123.       End
  124.    End
  125.    Begin CommonDialog cd 
  126.       CancelError     =   -1  'True
  127.       DefaultExt      =   ".ini"
  128.       Filter          =   "All Files (*.*)|*.*|Ini Files (*.ini)|*.ini"
  129.       InitDir         =   "c:\"
  130.       Left            =   0
  131.       Top             =   360
  132.    End
  133.    Begin Menu zFile 
  134.       Caption         =   "&File"
  135.       Begin Menu zf 
  136.          Caption         =   "&Open..."
  137.          Index           =   1
  138.       End
  139.       Begin Menu zf 
  140.          Caption         =   "&Save"
  141.          Index           =   2
  142.       End
  143.       Begin Menu zf 
  144.          Caption         =   "Save &As..."
  145.          Index           =   3
  146.       End
  147.       Begin Menu zf 
  148.          Caption         =   "Backup Ini Files"
  149.          Index           =   4
  150.       End
  151.       Begin Menu zf 
  152.          Caption         =   "-"
  153.          Index           =   5
  154.       End
  155.       Begin Menu zf 
  156.          Caption         =   "E&xit"
  157.          Index           =   6
  158.       End
  159.       Begin Menu zi 
  160.          Caption         =   "-"
  161.          Index           =   0
  162.       End
  163.       Begin Menu zi 
  164.          Caption         =   "autoexec.bat"
  165.          Index           =   1
  166.          Shortcut        =   {F5}
  167.       End
  168.       Begin Menu zi 
  169.          Caption         =   "config.sys"
  170.          Index           =   2
  171.          Shortcut        =   {F6}
  172.       End
  173.       Begin Menu zi 
  174.          Caption         =   "system.ini"
  175.          Index           =   3
  176.          Shortcut        =   {F7}
  177.       End
  178.       Begin Menu zi 
  179.          Caption         =   "win.ini"
  180.          Index           =   4
  181.          Shortcut        =   {F8}
  182.       End
  183.    End
  184.    Begin Menu zedit 
  185.       Caption         =   "&Edit"
  186.       Begin Menu ze 
  187.          Caption         =   "Cu&t"
  188.          Index           =   0
  189.          Shortcut        =   ^X
  190.       End
  191.       Begin Menu ze 
  192.          Caption         =   "&Copy"
  193.          Index           =   1
  194.          Shortcut        =   ^C
  195.       End
  196.       Begin Menu ze 
  197.          Caption         =   "&Paste"
  198.          Index           =   2
  199.          Shortcut        =   ^V
  200.       End
  201.       Begin Menu ze 
  202.          Caption         =   "De&lete"
  203.          Index           =   3
  204.          Shortcut        =   {DEL}
  205.       End
  206.       Begin Menu ze 
  207.          Caption         =   "-"
  208.          Index           =   4
  209.       End
  210.       Begin Menu ze 
  211.          Caption         =   "Select &All"
  212.          Index           =   5
  213.       End
  214.       Begin Menu ze 
  215.          Caption         =   "-"
  216.          Index           =   6
  217.       End
  218.       Begin Menu ze 
  219.          Caption         =   "Time/&Date"
  220.          Index           =   7
  221.       End
  222.    End
  223.    Begin Menu zo 
  224.       Caption         =   "&Font"
  225.       Index           =   3
  226.       Begin Menu zFontName 
  227.          Caption         =   "FontName"
  228.          Index           =   0
  229.       End
  230.    End
  231. Option Explicit
  232. Dim i%, r%, s$
  233. Dim dirty%(0 To 1)
  234. Dim inifile$(0 To 1)
  235. Dim tlines%(0 To 1)
  236. Dim showlist%
  237. Dim tb As TabData
  238. Dim captions$()
  239. Dim ftb As TabData
  240. Sub BackupIni ()
  241. Dim f$
  242. screen.MousePointer = 11
  243. s$ = App.Path & "\backup"
  244. If Dir(s$, 16) = "" Then MkDir s$
  245. CopyFile "c:\autoexec.bat", "autoexec.xxx"
  246. CopyFile "c:\config.sys", "config.xxx"
  247. CopyFile "c:\windows\system.ini", "system.xxx"
  248. CopyFile "c:\windows\win.ini", "win.xxx"
  249. screen.MousePointer = 0
  250. End Sub
  251. Sub CopyFile (Filename$, temp$)
  252. Dim fnum%, lng&, f$, t$
  253. On Error GoTo cerr
  254. fnum = FreeFile ' get next handle number
  255. Open Filename$ For Binary As #fnum%
  256.     lng& = LOF(fnum)
  257.     s$ = String$(lng, " ")
  258.     Get #fnum%, , s$
  259. Close #fnum%
  260. fnum = FreeFile ' get next handle number
  261. f$ = App.Path & "\backup\" & temp$
  262. t$ = Dir(f$)
  263. If t$ <> "" Then
  264.     Kill f$
  265. End If
  266. Open f$ For Binary As #fnum%
  267.     Put #fnum, , s$
  268. Close #fnum
  269. Exit Sub
  270. cerr:
  271. Close #fnum
  272. MsgBox "Error copying " & Filename$
  273. Exit Sub
  274. End Sub
  275. Sub Form_Load ()
  276. crlf$ = Chr$(13) + Chr$(10)
  277. zFontName(0).Caption = screen.Fonts(0)
  278. For i = 1 To screen.FontCount - 1
  279.     Load zFontName(i)
  280.     zFontName(0).Caption = screen.Fonts(i)
  281. Initialize
  282. iniviewer.Show
  283. zi_click 1
  284. End Sub
  285. Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer)
  286. Dim msg, Filename
  287. Dim response As Integer
  288. For i = 0 To 1
  289. If dirty(i) Then
  290.     Filename = inifile(i)
  291.     msg = "The text in [" & Filename & "] has changed."
  292.     msg = msg & crlf$
  293.     msg = msg & "Do you want to save the changes?"
  294.     r = MsgBox(msg, 51, "IniViewer")
  295.     Select Case r
  296.     ' Yes
  297.     Case 6
  298.     Filename = GetFName(2)
  299.     'If the user did notspecify a file name,
  300.     'cancel the unload; otherwise, save it.
  301.     If Filename = "" Then
  302.     Cancel = True
  303.     Else
  304.     SaveFileAs (Filename)
  305.     End If
  306.     ' User selects No
  307.     ' Ok to unload
  308.     Case 7
  309.     GoTo skip
  310.     ' User selects Cancel
  311.     ' Cancel the unload
  312.     Case 2
  313.     Cancel = True
  314.     Exit For
  315.     End Select
  316. skip:
  317. End If
  318. End Sub
  319. Function GetFName (n%)
  320. On Error Resume Next
  321.     cd.Action = n%
  322.     If Err <> 32755 Then      'User cancelled dialog
  323.     GetFName = cd.Filename
  324.     Else
  325.     GetFName = ""
  326.     End If
  327. End Function
  328. Sub Initialize ()
  329. '===create an array of controls=======
  330. ReDim captions(0 To 3)
  331. captions(0) = "autoexec.bat"
  332. captions(1) = "config.sys"
  333. captions(2) = "system.ini"
  334. captions(3) = "win.ini"
  335. '===fill in the fields of the struct=====================
  336. tb.num = 3              'number of tabs
  337. tb.active = 0           'initial focus
  338. tb.cols = 4             'number of tabs in each row
  339. tb.insetx = 4
  340. tb.insety = 4
  341. DefineControl Me, tabbox, invbox, page, tb
  342. End Sub
  343. Sub OpenIniFile (f$, ndx%)
  344. Dim fnum%, lng&
  345. 'If lbox.Visible Then zb_click 13
  346. On Error GoTo ierr
  347. fnum = FreeFile ' get next handle number
  348. Open f$ For Binary As #fnum%
  349.     lng& = LOF(fnum)
  350.     s$ = String$(lng, " ")
  351.     Get #fnum%, , s$
  352. Close #fnum%
  353. t(ndx%) = s$
  354. tlines(ndx) = SendMessage(t(ndx).hWnd, EM_GETLINECOUNT, 0, 0&)
  355. ttl(ndx%) = Format(tlines(ndx), "@@@@") & " : " & LCase(f$)
  356. dirty(ndx%) = 0
  357. Exit Sub
  358. ierr:
  359. MsgBox "Can't open " & f$
  360. Exit Sub
  361. End Sub
  362. Sub SaveFileAs (Filename)
  363. On Error Resume Next
  364. s = Dir(Filename)
  365. If s <> "" Then
  366.     If MsgBox("[" & UCase(Filename) & "]" & "already exists." & crlf & crlf & " Overwrite?", 36, "INIVIEWER") <> 6 Then Exit Sub
  367. End If
  368. Open Filename For Output As #1
  369. s = t(active)
  370. screen.MousePointer = 11
  371. Print #1, s
  372. Close #1
  373. screen.MousePointer = 0
  374. If Err Then MsgBox Error, 48, App.Title
  375. End Sub
  376. Sub t_Change (Index As Integer)
  377. dirty(Index) = True
  378. End Sub
  379. Sub t_GotFocus (Index As Integer)
  380. Dim other%
  381. active = Index
  382. If active = 0 Then other = 1
  383. t(active).ForeColor = QBColor(0)'black
  384. t(other).ForeColor = QBColor(8)
  385. End Sub
  386. Sub tabbox_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  387. TabClick Button, X, Y, tabbox, captions(), tb
  388. zi_click tb.active + 1
  389. t(0).SetFocus
  390. End Sub
  391. Sub tabbox_Paint ()
  392. DrawText tabbox, captions(), tb
  393. End Sub
  394. Sub ttl_Click (Index As Integer)
  395. 'caption labels for the files
  396. End Sub
  397. Sub ze_click (Index As Integer) 'edit
  398. Select Case Index
  399. Case 0
  400.     ClipBoard.SetText t(active).SelText
  401.     t(active).SelText = ""
  402. Case 1
  403.     ClipBoard.SetText t(active).SelText
  404. Case 2
  405.     t(active).SelText = ClipBoard.GetText()
  406. Case 3
  407.   If t(active).SelStart <> Len(t(active).Text) Then
  408.     ' If nothing is selected, extend selection by one.
  409.     If t(active).SelLength = 0 Then
  410.       t(active).SelLength = 1
  411.       ' If cursor is on a blank line, extend selection by two.
  412.       If Asc(t(active).SelText) = 13 Then
  413.     t(active).SelLength = 2
  414.       End If
  415.     End If
  416.     ' Delete selected text.
  417.     t(active).SelText = ""
  418.   End If
  419. Case 5
  420.     t(active).SelStart = 0
  421.     t(active).SelLength = Len(t(active).Text)
  422. Case 7
  423. t(active).SelStart = 0: t(active).SelLength = 0
  424. If Right$(t(active).Tag, 3) = "ini" Then
  425.     s = "; "
  426.     s = "REM "
  427. End If
  428. t(active).SelText = s & Now & crlf$
  429. End Select
  430. End Sub
  431. Sub zf_click (Index As Integer)
  432. Select Case Index
  433. Case 1'open
  434.     s = GetFName(1)
  435.     If s$ <> "" Then
  436.     t(active).Tag = s$
  437.     OpenIniFile s$, active
  438.     End If
  439. Case 2'save
  440.     s = t(active).Tag
  441.     If s = "" Then Beep: Exit Sub
  442.     If Not dirty(active) Then MsgBox "[" & UCase(s$) & "]" & crlf$ & crlf$ & "is up to date.", , "INIVIEWER": Exit Sub
  443.     If s$ <> "" Then SaveFileAs (s$)
  444. Case 3'saveas
  445.     s = t(active).Tag
  446.     If s = "" Then Beep: Exit Sub
  447.     cd.Filename = s
  448.     s = GetFName(2)
  449.     If s <> "" Then
  450.     t(active).Tag = s
  451.     SaveFileAs (s)
  452.     End If
  453. Case 4
  454.     BackupIni
  455. Case 6'exit
  456. Unload Me
  457. End Select
  458. End Sub
  459. Sub zFontName_Click (Index As Integer)
  460. For i = 0 To 1
  461.     t(i).FontName = zFontName(Index).Caption
  462. End Sub
  463. Sub zi_click (Index As Integer)
  464. Select Case Index
  465. Case 1
  466.     t(0).Tag = "c:\autoexec.bat"
  467.     t(1).Tag = App.Path & "\backup\autoexec.xxx"
  468. Case 2
  469.     t(0).Tag = "c:\config.sys"
  470.     t(1).Tag = App.Path & "\backup\config.xxx"
  471. Case 3
  472.     t(0).Tag = "c:\windows\system.ini"
  473.     t(1).Tag = App.Path & "\backup\system.xxx"
  474. Case 4
  475.     t(0).Tag = "c:\windows\win.ini"
  476.     t(1).Tag = App.Path & "\backup\win.xxx"
  477. End Select
  478. OpenIniFile CStr(t(0).Tag), 0
  479. OpenIniFile CStr(t(1).Tag), 1
  480. t(0).SetFocus
  481. End Sub
  482. Sub zo_click (Index As Integer) 'font
  483. End Sub
  484.